﻿Imports System.Data.SqlClient

Public Class frmNombres

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim cnconn As New SqlConnection
        Dim strSql As String
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader

        Try
            cnconn.ConnectionString = CitraConnection
            strSql = "SELECT IdLiquidacion,CodigoOperador FROM Liquidacion WHERE convert(varchar,fecha,101)>='10/25/2012' AND convert(varchar,fecha,101)<='10/31/2012'"

            cmdBuscar.Connection = cnconn
            cmdBuscar.CommandText = strSql

            cnconn.Open()
            rdBuscar = cmdBuscar.ExecuteReader

            Dim IdEmpleado As Integer
            Dim Nombre As String
            Dim CodigoOperador As String
            Dim CaracterInicial As String
            Dim Folio As Integer

            Do While rdBuscar.Read()
                CodigoOperador = rdBuscar("CodigoOperador")
                CaracterInicial = Mid(CodigoOperador, 1, 1)
                Folio = rdBuscar("IdLiquidacion")
                If CaracterInicial = "B" Then
                    CodigoOperador = Mid(CodigoOperador, 2)
                End If
                IdEmpleado = BuscarIntDatoCitra("OperadoresGlobal", "IdOperador", "Codigo='" & CodigoOperador & "'")
                Nombre = BuscarStrDatoCitra("OperadoresGlobal", "Nombre", "Codigo='" & CodigoOperador & "'")
                Call SetSqlCitra("UPDATE Liquidacion SET IdOperador=" & IdEmpleado & ", CodigoOperador='" & CodigoOperador & "', NombreOperador='" & Nombre & "' WHERE IdLiquidacion=" & Folio)
            Loop
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        Finally
            If cnconn.State = ConnectionState.Open Then
                cnconn.Close()
            End If
        End Try

        MsgBox("Registros actualizados correctamente", MsgBoxStyle.Information, "Aviso")
    End Sub
End Class